#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>


void main(int argc, char * argv[])
{
	int fd = 0;
	FILE *fp;
	const char *filename = "/home/ic14b035/bes-2015-hms/abgabe_2/beliebiges_file.txt";
	const char *filename2 = "/home/ic14b035/bes-2015-hms/abgabe_2/kurzes_textfile.txt";

	/* open-dup2-Spielerei */

	/*if(pipe(fd) == -1)
		printf("error pipe function");*/

	printf("START OPEN FILE\n");

	/*if((fp = open(filename, "w")) == NULL)
	{
		printf("error fopen\n");
	}
	if(fprintf(fp, "testtext\n") < 0)
	{
		printf("error writing to file");
	}*/

	fd = open(filename, "w");

	if(dup2(fd, STDOUT_FILENO) == -1)
	{
		printf("error dup2");
	}
	else
	{
		close(fd);
		execl("/bin/cat", "cat", filename2, (char *) NULL);
	}

	/*if(fclose(fp) == -1)
	{
		printf("error fclose\n");
	}*/


}
